package 字符串.easy;

/**
 * LWZ TODO : 2020/8/21
 * 不是很懂
 */

/**
 * @author Lw中
 * @date 2020/8/21 8:01
 */
public class QiBaBa {

    public static int rotatedDigits(int N) {
        // Count how many n in [1, N] are good.
        int ans = 0;
        for (int n = 1; n <= N; ++n) {
            if (good(n, false)) {
                ans++;
            }
        }
        return ans;
    }

    // 如果n为好数返回true
    // The flag is true iff we have an occurrence of 2, 5, 6, 9.
    public static  boolean good(int n, boolean flag) {
        if (n == 0) {
            return flag;
        }

        int d = n % 10;
        if (d == 3 || d == 4 || d == 7) {
            return false;
        }
        if (d == 0 || d == 1 || d == 8) {
            return good(n / 10, flag);
        }
        return good(n / 10, true);
    }

    public static void main(String[] args) {
        int i = rotatedDigits(10);
        System.out.println(i);
    }

}
